// Task 处理异步任务
const fs = require('fs')
const { task } = require('folktale/concurrency/task')
// 柯里化的方法：split、find
const { split, find } = require('lodash/fp')
function readFile (filename) {
  // 返回一个函子
  return task(resolver => {
    fs.readFile(filename, 'utf-8', (err, data) => {
      if (err) {
        resolver.reject(err)
      }
      resolver.resolve(data)
    })
  })
}

readFile('package.json')
.map(split('\n'))
.map(find(x => x.includes('version')))
.run()
.listen({
  onRejected: err => {
    console.log(err)
  },
  onResolved: value => {
    console.log(value) //   "version": "1.0.0",
  }
})